package com.example.hangzhou.welbeing.mytestdemoapp.animation.animationActivity;

import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.transition.Explode;
import android.transition.Transition;
import android.transition.TransitionManager;
import android.view.View;

import com.example.hangzhou.welbeing.mytestdemoapp.R;
import com.example.hangzhou.welbeing.mytestdemoapp.animation.animationAdapter.AnimatedTransitionsExplodeAndPropagationAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 杭州惟君医疗科技有限公司15
 * Created by 20433 on 2018/5/9
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class AnimatedTransitionsExplodeAndPropagationActivity extends AppCompatActivity {
    @Bind(R.id.activity_animation_transition_explode_and_propagation_recyclerview)
    RecyclerView activityAnimationTransitionExplodeAndPropagationRecyclerview;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation_transition_explode_and_propagation);
        ButterKnife.bind(this);
        GridLayoutManager   mLayoutManager=new GridLayoutManager(this,3,GridLayoutManager.VERTICAL,false);//设置为一个3列的
        activityAnimationTransitionExplodeAndPropagationRecyclerview.setLayoutManager(mLayoutManager);
        AnimatedTransitionsExplodeAndPropagationAdapter animatedTransitionsExplodeAndPropagationAdapter =   new AnimatedTransitionsExplodeAndPropagationAdapter();
        activityAnimationTransitionExplodeAndPropagationRecyclerview.setAdapter(animatedTransitionsExplodeAndPropagationAdapter);
        animatedTransitionsExplodeAndPropagationAdapter.setOnItemClickListener(new AnimatedTransitionsExplodeAndPropagationAdapter.OnItemClickListener() {
            @Override
            public void onClick(View view) {
                Rect viewRect = new Rect();
                view.getGlobalVisibleRect(viewRect);
                Explode explode = new Explode();
                explode.setEpicenterCallback(new Transition.EpicenterCallback() {
                    @Override
                    public Rect onGetEpicenter(Transition transition) {
                        return viewRect;
                    }
                });
                explode.setDuration(1000);
                TransitionManager.beginDelayedTransition(activityAnimationTransitionExplodeAndPropagationRecyclerview, explode);
                activityAnimationTransitionExplodeAndPropagationRecyclerview.setAdapter(null);
            }
        });

    }
}
